/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.employee.controller;

import com.admin.model.EventLibraryFacadeLocal;
import com.entities.EventLibrary;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author NguyenVan
 */
@Stateless
public class EventLibraryBean implements EventLibraryBeanRemote {

    @EJB
    private EventLibraryFacadeLocal eventLibraryFacade;

    public EventLibraryBean() {
    }

    private EventLibraryFacadeLocal getRemote() {
        try {
            InitialContext ict = new InitialContext();
            EventLibraryFacadeLocal remote = (EventLibraryFacadeLocal) ict.lookup("java:global/BluePumpkinEJB/EventLibraryFacade!com.employee.model.EventLibraryFacadeLocal");
            return remote;
        } catch (NamingException ex) {
            Logger.getLogger(EventLibraryBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public String Description(int id) {
        EventLibraryFacadeLocal remote = getRemote();
        EventLibrary ev = remote.find(id);
        if (ev != null) {
            return ev.getDescription();
        }
        return null;
    }

    @Override
    public List<String> ListEventLibrary() {
        List<String> jsonlist = new ArrayList<String>();
        jsonlist = eventLibraryFacade.fillEventsDataTable();
        return jsonlist;
    }
}
